﻿using HPCERP.BusinessObject;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using HPCERP.Model;
using HPCERP.SetupDatabase;

namespace HPCERP.BusinessObject.Tests
{
    
    
    /// <summary>
    ///This is a test class for BankBOTest and is intended
    ///to contain all BankBOTest Unit Tests
    ///</summary>
    [TestClass()]
    public class BankBOTest
    {


        private TestContext testContextInstance;
        private Company company;
        private int id_Company;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        [TestInitialize()]
        public void MyTestInitialize()
        {
            company = TestCompany.GetObject();
            id_Company = company.ID_Company;
        }
        
        
        
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion




        /// <summary>
        ///A test for Delete
        ///</summary>
        [TestMethod()]
        public void DeleteTest()
        {
            BankBO target = new BankBO(); // TODO: Initialize to an appropriate value
            foreach (Bank bank in target.GetList(id_Company))
            {
                if (bank.Name == "Test Bank")
                {
                    target.Delete(bank.ID_Bank);
                }
            }
        }

        /// <summary>
        ///A test for GetList
        ///</summary>
        [TestMethod()]
        public void GetListTest()
        {
            BankBO target = new BankBO(); 
             Bank[] actual;
            actual = target.GetList(id_Company);
            Assert.AreEqual((actual.GetLength(0) >=0), true);
        }

        /// <summary>
        ///A test for Insert
        ///</summary>
        [TestMethod()]
        public void InsertTest()
        {
            BankBO target = new BankBO(); // TODO: Initialize to an appropriate value
            Bank bank = new Bank(); // TODO: Initialize to an appropriate value
            bank.Name = "Test Bank";
            bank.Company = TestCompany.GetObject();
            target.Insert(bank);
        }

        /// <summary>
        ///A test for Update
        ///</summary>
        [TestMethod()]
        public void UpdateTest()
        {
            BankBO target = new BankBO(); 
            foreach (Bank bank in target.GetList(id_Company))
            {
                bank.Name = bank.Name + " Update";
                target.Update(bank);
            }
            foreach (Bank bank in target.GetList(id_Company))
            {
                bank.Name = bank.Name.Replace(" Update","");
                target.Update(bank);
            }
        }
    }
}
